<link rel="stylesheet" type="text/css" href="css/validationEngine.jquery.css">
<link rel="stylesheet" type="text/css" href="css/template.css">

<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="js/jquery.validationEngine.js"></script>
<script>

jQuery(document).ready(function($) {
jQuery("#formID").validationEngine();
});

</script>

<?php
$sql="SELECT substr( QUYEN,12, 1 ) as mq
FROM qldl_tai_khoan
WHERE ten_dang_nhap = '".$_SESSION['username']."'";
	$query = @mysql_query($sql,$conn);
	$row = @mysql_fetch_array($query);
	if($row['mq']==1){
	 header('Location: index.php?page=id_add_admin'); 
	}
	else {
			echo  "<script>alert ('Bạn không có quyền truy cập trang này!')</script>"; 
	echo "<meta http-equiv='refresh' content='0;url= index.php'>";
	}
?>
<div class="cpanel-right-tttk">
  <div id="panel-sliders" class="pane-sliders">
    <div class="panel">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" style=" padding:10px;">
        <thead>
        <tr style=" padding-bottom:10px;">
        <th colspan="3" align="left" style="padding-bottom:10px;">QUẢN LÍ NGƯỜI DÙNG</th>
        </tr> 
        </thead>
        <tr valign="top" style="padding:5px;">
          <td width="42%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <form action="" method="post" name="formID" id="formID" enctype="multipart/form-data">
            <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="2"> Thông tin người dùng</th>
                </tr>
              </thead>
              <tbody>
               <?php  
	$sql="select * from qldl_tai_khoan where TEN_DANG_NHAP='".$_GET['id_edit_admin']."'";
	$query = @mysql_query($sql,$conn);	
	$row = @mysql_fetch_array($query);
		
  ?>    
                <tr>
                  <td width="122">Tên đăng nhập</td>
                  <td width="328"><input type="text" readonly="readonly" name="txt_tdn" id="txt_tdn" value="<?php echo $row['TEN_DANG_NHAP'];?>" /></td>
                </tr>
                <tr>
                  <td>Email</td>
                  <td><input type="text" name="txt_email" id="txt_email" readonly="readonly" value="<?php echo $row['EMAIL'];?>"  /></td>
                  </tr>
                <tr>
                  <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <thead>
                      <tr>
                        <th colspan="6">Phân quyền người dùng</th>
                        </tr>
                        <?php 
					if(isset($_POST['btn_add'])){
					$email = $_POST['txt_email'];
					$tdn = $_GET['id_edit_admin'];
					if(isset($_POST['ck_t'])){
					$q1=1;
					}else $q1=0;
					if(isset($_POST['ck_kt'])){
					$q2=1;
					}else $q2=0;
					if(isset($_POST['ck_dd'])){
					$q3=1;
					}else $q3=0;
					if(isset($_POST['ck_ks'])){
					$q4=1;
					}else $q4=0;
					if(isset($_POST['ck_pt'])){
					$q5=1;
					}else $q5=0;
					if(isset($_POST['ck_gt'])){
					$q6=1;
					}else $q6=0;
					if(isset($_POST['ck_tt'])){
					$q7=1;
					}else $q7=0;
					if(isset($_POST['ck_km'])){
					$q8=1;
					}else $q8=0;
					if(isset($_POST['ck_cn'])){
					$q9=1;
					}else $q9=0;
					if(isset($_POST['ck_bn'])){
					$q10=1;
					}else $q10=0;
					if(isset($_POST['ck_qlnd'])){
					$q11=1;
					}else $q11=0;
					if(isset($_POST['ck_ttnd'])){
					$q12=1;
					}else $q12=0;
					if(isset($_POST['ck_ttp'])){
					$q13=1;
					}else $q13=0;
					if(isset($_POST['ck_qg'])){
					$q14=1;
					}else $q14=0;
					if(isset($_POST['ck_lhdt'])){
					$q15=1;
					}else $q15=0;
					$pq=$q1."".$q2."".$q3."".$q4."".$q5."".$q6."".$q7."".$q8."".$q9."".$q10."".$q11."".$q12."".$q13."".$q14."".$q15;
					$sql = "update qldl_tai_khoan set				
								EMAIL='$email',
								QUYEN='$pq'
								where TEN_DANG_NHAP='$tdn'
							";
					$query = @mysql_query($sql,$conn);
					if($query)echo "<script>alert ('Cập nhật thông tin thành công.')</script>";	
					else echo "<script>alert ('Lỗi cập nhật thông tin!')</script>";

					}
					?>
                      </thead>
                    <tbody>
                    
                      <tr>
                     
                        <td width="11%">
                         <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 1, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 1, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_t" id="ck_t" value="1" />
                          <?php }
						  else {
						  ?>
                          <input type="checkbox" name="ck_t" id="ck_t" value="1" />
                          <?php }?>
                          <p>                        Tour</p></td>
                        <td width="14%">
                          <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 2, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 2, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_kt" id="ck_kt" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_kt" id="ck_kt" value="1" />
                           <?php }?>
                          <p>                        Kiểu tour</p></td>
                        <td width="17%">
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 3, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 3, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_dd" id="ck_dd" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_dd" id="ck_dd" value="1" />
                           <?php }?>
                          <p>                        Địa điểm dl</p></td>
                        <td width="17%">
                          <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 4, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 4, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_ks" id="ck_ks" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_ks" id="ck_ks" value="1" />
                           <?php }?>
                        
                          <p>                        Khách sạn</p></td>
                        <td width="22%">
                           <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 5, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 5, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_pt" id="ck_pt" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_pt" id="ck_pt" value="1" />
                           <?php }?>
                          
                          <p>                        Phương tiện</p></td>
                        <td width="19%">
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 6, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 6, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_gt" id="ck_gt" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_gt" id="ck_gt" value="1" />
                           <?php }?>
                          
                          <p>                        Giới thiệu</p></td>
                        </tr>
                      <tr>
                        <td>
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 7, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 7, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_tt" id="ck_tt" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_tt" id="ck_tt" value="1" />
                           <?php }?>
                        
                          <p>Tin tức</p></td>
                        <td>
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 8, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 8, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_km" id="ck_km" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_km" id="ck_km" value="1" />
                           <?php }?>
                        
                          <p>Khuyến mãi</p></td>
                        <td>
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 9, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 9, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_cn" id="ck_cn" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_cn" id="ck_cn" value="1" />
                           <?php }?>
                        
                          <p>Cẩm nang dl</p></td>
                        <td>
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 10, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 10, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_bn" id="ck_bn" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_bn" id="ck_bn" value="1" />
                           <?php }?>
                        
                          <p>Banner</p></td>
                        <td>
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 11, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 11, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_qlnd" id="ck_qlnd" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_qlnd" id="ck_qlnd" value="1" />
                           <?php }?>
     
                          <p>QL người dùng</p></td>
                        <td>
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 12, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 12, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_ttnd" id="ck_ttnd" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_ttnd" id="ck_ttnd" value="1" />
                           <?php }?>
                        
                          <p>Thông tin người dùng</p></td>
                        </tr>
                      <tr>
                        <td>
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 13, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 13, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_ttp" id="ck_ttp" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_ttp" id="ck_ttp" value="1" />
                           <?php }?>
                        
                          <p>Tỉnh/thành phố</p></td>
                        <td>
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 14, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 14, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_qg" id="ck_qg" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_qg" id="ck_qg" value="1" />
                           <?php }?>
                        
                          <p>Quốc gia</p></td>
                        <td>
                        <?php
					  	$sql_c1= "SELECT SUBSTRING( QUYEN, 15, 1 ) FROM qldl_tai_khoan
										WHERE TEN_DANG_NHAP ='".$_GET['id_edit_admin']."'";
					  	$query_c1 = @mysql_query($sql_c1,$conn);	
							$row_c1= @mysql_fetch_array($query_c1);
	
							if($row_c1['SUBSTRING( QUYEN, 15, 1 )']=='1'){
					  ?>
                          <input type="checkbox" checked="checked" name="ck_lhdt" id="ck_lhdt" value="1" />
                          <?php }
						   else {?>
                           <input type="checkbox" name="ck_lhdt" id="ck_lhdt" value="1" />
                           <?php }?>
                        
                        <p>Liên hệ đặt tour</p></td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        </tr>
                      </tbody>
                    </table></td>
                </tr>
                <tr>
                  <td colspan="2"><input type="submit" name="btn_add" id="btn_add" value="Lưu" />
                    <input type="reset" name="btn_huy" id="btn_huy" value="Hủy" />
                    </td>
                </tr>
                  
              </tbody>
            </table>
            </form>
          </div></td>
          
          <td width="12%" align="center">&nbsp;</td>
          <td width="46%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="4"> Danh sách người dùng</th>
                    <?php
			   			include('quantri_taikhoan/del.php');?>
                </tr>
              </thead>

              <tbody>
              <form action="" method="post" name="form_view" id="form_view">
                <tr>
                  <td width="52">Stt</td>
                  <td width="178">Tên đăng nhập</td>
                  <td width="129">Email</td>
                  <td width="129">Cập nhật</td>
                </tr>
                <?php  
	$stt=0;
	$sql1="select * from qldl_tai_khoan order by TEN_DANG_NHAP".$_GET['sort'];
	$query1 = @mysql_query($sql1,$conn);	
	if(!$query1) echo "Query error to display.";
	else while($row1 = @mysql_fetch_array($query1)){
		$stt++;
		?>
                <tr>
                  <td><?php echo $stt;?></td>
                  <td><?php echo $row1['TEN_DANG_NHAP'];?></td>
                  <td><?php echo $row1['EMAIL'];?></td>
                  <td valign="middle" align="center">
                  <a href="index.php?page=id_edit_admin&amp;id_edit_admin=<?php echo $row1['TEN_DANG_NHAP'];?>">Sửa</a>||
                  <a href="#" onclick= "Del_Info('index.php?page=id_add_admin&amp;id_del_admin=<?php echo $row1['TEN_DANG_NHAP'];?>');">Xóa</a>
                  </td>
                </tr>
                <?php } ?>
                </form>
              </tbody>
            </table>
          </div></td>
        </tr>
      </table>
    </div>
  </div>
</div>
